package com.zdsoft.blp.zongbuju.wode.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by pc on 2016/9/6.
 */
public class SheZhiZHActivity extends BaseActivity implements NetCallback{
    private FanHuiView fh;
    private EditText et_name,et_password,et_cpassword;
    private Button bt_wancheng;
    private static final Integer MEMBERREGISTERED =1;
    @Override
    protected void init() {
        setContentView(R.layout.shezhizhanghao_wode);
        fh = find(R.id.fh);
        et_name = find(R.id.et_name);
        et_password = find(R.id.et_password);
        et_cpassword = find(R.id.et_cpassword);
        bt_wancheng = find(R.id.bt_wancheng);
        fh.getTv_title().setText("设置账号");
        final Intent intent = getIntent();
        bt_wancheng.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = et_name.getText().toString().trim();
                String password = et_password.getText().toString().trim();
                String cpassword = et_cpassword.getText().toString().trim();
                if(!"".equals(name)&&password.equals(cpassword)&&!"".equals(password)){
                    Net net = new Net();
                    net.url = API.MEMBER_URL;
                    net.nameSpace = API.MEMBER_NAMESPACE;
                    net.methodName = API.MEMBERREGISTERED;
                    Map<String, Object> map = new HashMap<>();
                    map.put("mobile", intent.getStringExtra("phone").toString().trim());
                    map.put("nickName", et_name.getText().toString().trim());
                    map.put("password", et_password.getText().toString().trim());
                    net.parms = map;
                    net.code = MEMBERREGISTERED;
                    getServer(net, SheZhiZHActivity.this);
                }else {
                    Toast.makeText(getApplicationContext(),"昵称或者密码不能为空", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void onResponse(boolean flag, int code, String res) {
        if(flag&&code==MEMBERREGISTERED){
            Log.e("asd",res);//未完成
        }
    }
}
